{extend name='base' /}

{block name='main'}
<link rel="stylesheet" href="__CSS__/booklist.css">
<link rel="stylesheet" href="__CSS__/booktable.css">
<style>
    .main {
        background: url("__IMG__/list_bg.jpg") left top repeat-y;
    }
</style>
<div class="row m-0 mt-3 main">
    {include file='user/user_left'}
    <div class="right flex-1 table-responsive">
        <div class="d-flex align-items-center mb-3">
            <div class="" style="flex: 1;">您已创建了 <span class="text-danger">{php}echo count($address){/php}</span> 个收货地址，最多可以创建 <span class="text-danger">3</span> 个</div>
            <a href="{:url('User/myaddress')}" class="btn btn-danger btn-sm">添加新地址</a>
        </div>
        <table class="tb w-100">
            <thead>
            <tr>
                <th>姓名</th>
                <th>手机号</th>
                <th>地址</th>
                <th>状态</th>
                <th width="120">操作</th>
            </tr>
            </thead>
            <tbody>
            {foreach $address as $k => $v}
            <tr>
                <td>{$v['truename']}</td>
                <td>{$v['mobile']}</td>
                <td>{$v['address']}</td>
                <td>{if $v['is_default']==1}<a href="javascript:void(0)" style="font-size: 12px;" class="badge badge-info">默认</a>{else}{/if}</td>
                <td>
                    {if $v['is_default']==0}<a href="javascript:void(0);" onclick="setDefault('{$v["id"]}')" class="btn btn-link btn-danger btn-sm">默认</a>{/if}
                    <a href="{:url('User/myaddress')}?id={$v['id']}"  class="t btn-sm">编辑</a>
                    <a href="javascript:void(0);" onclick="delAddress('{$v["id"]}')" class="d tn-sm">删除</a>
                </td>
            </tr>
            {/foreach}
            </tbody>
        </table>
    </div>
</div>
{/block}

{block name='js'}
<script>
    function delAddress(id) {
        common("你确定要删除此记录吗？", "{:url('User/deladdress')}?id="+id)
    }

    function setDefault(id) {
        common("你确定要设置为默认吗？", "{:url('User/setdefault')}?id="+id)
    }
</script>
{/block}